var r = require('../@babel/runtime/helpers/typeof');
const TOWNDATA = [
  '高新区',
  '开发区',
  '牛山街道',
  '石榴街道',
  '安峰镇',
  '白塔埠镇',
  '房山镇',
  '洪庄镇',
  '黄川镇',
  '李埝乡',
  '平明镇',
  '青湖镇',
  '曲阳镇',
  '山左口镇',
  '石湖乡',
  '石梁河镇',
  '双店镇',
  '桃林镇',
  '驼峰乡',
  '温泉镇',
  '张湾乡',
];

module.exports = {
  isEmpty: function (e) {
    return (
      null == e ||
      ('string' == typeof e && '' === e.trim()) ||
      !(!Array.isArray(e) || 0 !== e.length) ||
      ('object' === r(e) && !Array.isArray(e) && 0 === Object.keys(e).length)
    );
  },

  /**
   * 时间戳格式化
   * @param {number} time
   * @returns {string} 时间 YYYY-MM-DD HH:mm:ss
   */
  formatDate: (time) => {
    const format = (n) => {
      return n < 10 ? '0' + n : n;
    };
    const date = new Date(time);
    const year = date.getFullYear();
    const month = format(date.getMonth() + 1);
    const day = format(date.getDate());
    const hour = format(date.getHours());
    const minute = format(date.getMinutes());
    const second = format(date.getSeconds());
    return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  },

  /**
   * 表单校验
   * @param {*} form
   * @param {*} rules
   * @returns Boolean
   */
  validateFields: (form, rules) => {
    for (const key in rules) {
      if (Object.prototype.hasOwnProperty.call(rules, key)) {
        const rule = rules[key];
        const el = form?.[key];
        let value = null;
        if (typeof el === 'boolean') {
          value = el;
        } else {
          value = form?.[key].toString();
        }
        if (!value && rule) {
          wx.showToast({ title: rule, icon: 'none' });
          return false;
        }
      }
    }
    return true;
  },

  getTownData: () => TOWNDATA,
};
